using System.Collections.Generic;

using FineCollection.Intf;




namespace FineCollection.Const
{
    /// <summary>
    /// Immutable empty set. 
    /// </summary>
    /// <typeparam name="T">type of an item.</typeparam>
    public class ConstOrderZero<T> : ConstZero<T>, RRandomSet<T>
    {

        public IComparer<T> Comparer { get; private set; }



        #region CONSTRUCTOR

        /// <summary>
        /// Trivial constructor.
        /// </summary>
        public ConstOrderZero()
        {
            this.Comparer = Comparer<T>.Default;
        }


        /// <summary>
        /// Trivial constructor that can specify a comparer.
        /// </summary>
        public ConstOrderZero(IComparer<T> comparer)
        {
            this.Comparer = comparer;
        }


        /// <summary>
        /// An instance of empty set.
        /// </summary>
        new public static readonly ConstOrderZero<T> zero = 
            new ConstOrderZero<T>();

        #endregion


        /// <summary>
        /// Does nothing.
        /// </summary>
        /// <param name="item">an item to look for 
        ///               (it will not be found because the set is empty).</param>
        /// <param name="found">false.</param>
        /// <param name="position">1.</param>
        /// <exception cref="NullItemsException">when the specified item is null.</exception>
        public void Find(T item, out bool found, out int position)
        {
            if (item == null)
                throw new NullItemsException();

            found = false;
            position = FirstIndex;
        }


        /// <summary>
        /// Always does nothing and returns <see cref="int.MinValue"/>.
        /// </summary>
        /// <param name="item">an item to look for 
        ///               (it will not be found because the set is empty).</param>
        /// <returns><see cref="int.MinValue"/>.</returns>
        public int IndexOf(T item)
        {
            return int.MinValue;
        }


        /// <summary>
        /// Creates a read-only ordered iterator.
        /// </summary>
        new public ROrderIterator<T> TakeIterator()
        {
            return orderIteratorOfZero;
        }


        private static readonly OrderIteratorOfZero<T> orderIteratorOfZero = 
            new OrderIteratorOfZero<T>();


        internal class OrderIteratorOfZero<TT> : IteratorOfZero<TT>, ROrderIterator<TT>
        {
            public JumpResult Jump(TT item)
            {
                return JumpResult.End;
            }
        }

    }
}